package com.bear.sgg.springboot_06_web.errorPageTest;

import com.bear.sgg.springboot_06_web.exception.MyErrorPathException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassNmae ErrorPageController
 * @Description 测试错误页面
 * @Author bear
 * @Date 2020/3/11 0011 下午 9:55
 */
@Controller
public class ErrorPageTestController {

    /**
     * 当输入参数不为true时会抛出异常，如果不定义一个ExceptionHandler来捕捉和处理这个异常会跳转到5xx错误页面
     * @param flag
     * @return
     */
    @GetMapping(value = "/page")
    @ResponseBody
    private String testErrorPage(@RequestParam("flag") String flag) {
        if (flag.equals("t")) {
            throw new MyErrorPathException("路径错误啊啊啊啊");
        } else {
            return "hello world";
        }
    }
}
